package com.web.controller;


import com.web.entity.LoginInfo;
import com.web.entity.Result;
import com.web.entity.User;
import com.web.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/login")
@CrossOrigin
public class LoginController {

    @Autowired
    private UserService userService;


    //http://localhost:8080/login?username=lisi&password=123456
    @PostMapping
    public Result login(@RequestBody User user) {
        log.info("用户登录：{}", user);
        LoginInfo user1 = userService.login(user);
        if (user1 != null) {
            return Result.success(user1);
        }
        return Result.error("用户名或密码错误");
    }

}
